package jmine.tec.cluster.dao;

import java.util.List;

import jmine.tec.cluster.domain.ClusterNode;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;

import bancosys.tec.persist.dao.BaseDAO;

/**
 * DAO do ClusterNode
 * @author ricardo
 *
 */
public class ClusterNodeDAO extends BaseDAO<ClusterNode> {

	/**
	 * 
	 * @param id o id do node
	 * @return true se o node é master do cluster; false, caso contrário.
	 */
	public boolean isMaster(Long id) {
		Criteria c = this.createCriteria()
				.setProjection(Projections.min("id"));

		@SuppressWarnings("rawtypes")
		List result = c.list();

		if (result.isEmpty()) {
			return false;
		}

		Long minId = (Long) result.get(0);
		return id.equals(minId);
	}
}
